package com.ruoyi.system.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.ProjectPurchaseOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

/**
 * 采购订单Mapper接口
 * 
 * @author ruoyi
 * @date 2025-03-11
 */
public interface ProjectPurchaseOrderMapper extends BaseMapper<ProjectPurchaseOrder>{

    @Select("SELECT " +
            " a.*, " +
            " IFNULL( b.number, 0 ) AS num  " +
            "FROM " +
            " ( " +
            " SELECT " +
            "  DATE_FORMAT( NOW( ), '%Y-%m-%d' ) AS date UNION " +
            " SELECT " +
            "  DATE_FORMAT( DATE_SUB( NOW( ), INTERVAL 1 DAY ), '%Y-%m-%d' ) AS date UNION " +
            " SELECT " +
            "  DATE_FORMAT( DATE_SUB( NOW( ), INTERVAL 2 DAY ), '%Y-%m-%d' ) AS date UNION " +
            " SELECT " +
            "  DATE_FORMAT( DATE_SUB( NOW( ), INTERVAL 3 DAY ), '%Y-%m-%d' ) AS date UNION " +
            " SELECT " +
            "  DATE_FORMAT( DATE_SUB( NOW( ), INTERVAL 4 DAY ), '%Y-%m-%d' ) AS date UNION " +
            " SELECT " +
            "  DATE_FORMAT( DATE_SUB( NOW( ), INTERVAL 5 DAY ), '%Y-%m-%d' ) AS date UNION " +
            " SELECT " +
            "  DATE_FORMAT( DATE_SUB( NOW( ), INTERVAL 6 DAY ), '%Y-%m-%d' ) AS date  " +
            " ) a " +
            " LEFT JOIN ( " +
            " SELECT " +
            "  DATE_FORMAT( NOW( ), '%Y-%m-%d' ) AS date, " +
            "  count( 1 ) AS number  " +
            " FROM " +
            "  project_purchase_order  " +
            " WHERE " +
            " created_time > DATE_SUB( NOW( ), INTERVAL 7 DAY )  " +
            " ) b ON ( a.date = b.date )")
    List<Map<String,Object>>  getChat();
}
